# !/usr/bin/env python
# encoding: utf-8
'''
  @author: HJW
  @license: (C) Copyright 2013-2017, Node Supply Chain Manager Corporation Limited.
  @contact: hejunwang01@126.com
  @file: django_email.py
  @time: 2024/1/7 0007 下午 21:24
  @desc:
  '''
import yagmail
import logging

logger = logging.getLogger(__name__)


class YaGmail:

    def __init__(self, sender, receivers, attachments=None):
        self.sender = sender
        self.receivers = receivers  # 接收邮件，可设置为你的QQ邮箱或者其他邮箱
        self.attachments = attachments

    def send(self):
        print("will send Email.")
        # 链接邮箱服务器
        yag = yagmail.SMTP(user=self.sender, password="QZNNEXWGKUOZGGAN", host='smtp.126.com')
        # 邮箱正文    # 文件地址，一定要精确到文件名，不能是文件夹

        contents = ['Beijing Green Star Little Green Man Shenzhen Branch, API interface test environment, '
                    'test environment routine test results',
                    ]
        # 发送邮件
        yag.send(self.receivers, subject='******API接口测试--接口测试结果*******', contents=contents,
                 attachments=self.attachments)
        print("Send Email Success.")

        logger.info('The email was sent successfully. Please check the results in your email later')


if __name__ == '__main__':
    sender = 'hejunwang01@126.com'
    receivers = ['287619892@qq.com', 'hejunwang02@126.com']
    sendemail = YaGmail(sender, receivers)
    sendemail.send()
    print('OK2')
